package com.example.baiducrabs.bayifu.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.Display;
import android.view.WindowManager;

/**
 * Created by Administrator on 2018/4/16.
 */

public class Common {


    //获取屏幕的宽度
    public static int getScreenWidth(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getWidth();
    }
    //获取屏幕的高度
    public static int getScreenHeight(Context context) {
        WindowManager manager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        return display.getHeight();
    }


    /**
     * 按正方形裁切图片
     */
    public static Bitmap ImageCrop(Bitmap bitmap, int Cutx,int Cuty, int Cutw, int Cuth, boolean isRecycled)
    {

        if (bitmap == null)
        {
            return null;
        }

        Bitmap bmp = Bitmap.createBitmap(bitmap,Cutx , Cuty, Cutw, Cuth, null, false);

        if (isRecycled && bitmap != null && !bitmap.equals(bmp)
                && !bitmap.isRecycled())
        {
            bitmap.recycle();
            bitmap = null;
        }
        // 下面这句是关键
        return bmp;

    }


}
